<%@ page contentType="text/html;charset=utf-8" language="java"
	pageEncoding="UTF-8" import="java.util.Date"%>
<!DOCTYPE html>
<html lang="en">
  <head>
     <%@include file="/WEB-INF/jsp/common/style.jsp"%>
  </head>
  <body>
    <div id="wrap">
    <input type="hidden" id="childNodeId" value="${model.productChildNode.id}"> 
   <div class="main_container" id="forms_page">
     	<div class="row-fluid">
          <div class="widget widget-padding span12">
           
           
            <div class="widget-forms clearfix"  style="padding-top:15px">
              	 <div class="form-horizontal" id="content">
              		<div class="control-group">
	                    <label class="control-label"><font color="red">*</font>产品节点:</label>
	                      <div class="controls">
	                        <select  id="nodeId" class="w300">
	                           	<option value="" <c:if test="${model.productChildNode.parentId==null}">selected="selected"</c:if>>全部</option>
						   			<c:forEach items="${model.nodes}" var="lo" varStatus="itemStatus">
						               <option value="${lo.id}" <c:if test="${model.productChildNode.parentId==lo.id}">selected="selected"</c:if>>${lo.nodeName}</option>
						        </c:forEach>  
	                        </select>
	                     </div>
	                  </div>
              	 
              	  <div class="control-group">
                    <label class="control-label" ><font color="red">*</font>子节点名称:</label>
                    <div class="controls">
                      <input name="childNodeName" id="childNodeName"  maxlength="100"  class="w300"  type="text" value="${model.productChildNode.nodeName}"   />                      
                    </div>
                  </div>
                 
                 <div class="control-group">
                    <label class="control-label"><font color="red">*</font>节点必填:</label>
                    <div class="controls">
                     <label class="radio">
                        <input name="isRequired"  type="radio" 
                        <c:if test="${model.productChildNode.isRequired==1}">checked="checked"</c:if>  
                        value="1">
                        	是(资料未上传不允许审批)
                      </label>
                      <label class="radio">
                        <input name="isRequired"  type="radio" 
                        <c:if test="${model.productChildNode.isRequired==0}">checked="checked"</c:if>  
                        value="0">
                     		否(不控制)
                      </label>
                    </div>
                  </div>
                  
                  <div class="control-group">
                    <label class="control-label"><font color="red">*</font>影响后续流程:</label>
                    <div class="controls">
                     <label class="radio">
                        <input name="isEffectChild"  type="radio" 
                        <c:if test="${model.productChildNode.isEffectChild==1}">checked="checked"</c:if>  
                        value="1">
                        	是(资料重新上传后续节点重新审批)
                      </label>
                      <label class="radio">
                        <input name="isEffectChild"  type="radio" 
                        <c:if test="${model.productChildNode.isEffectChild==0}">checked="checked"</c:if>  
                        value="0">
                     		否(不影响)
                      </label>
                    </div>
                  </div>
                
                 <div class="control-group">
                    <label class="control-label" >子节点模板:</label>
                    <div class="controls" style="padding-top: 5px;">
                      <a href="javascript:downLoad()"  fileName="${model.productChildNode.fileName}"  url="${model.productChildNode.templateUrl}" id="imagea">${model.productChildNode.fileName}</a>           
                    </div>
                  </div>
       
					
                  <div class="control-group">
                    <label class="control-label" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
                    <div class="controls">
                     <form enctype="multipart/form-data" method="post" name="uploadForm" id="uploadForm" style="height:30px;"> 
				    	<div style="width:20px;display:inline-block;;position:relative;height:30px;">
				　　　　		<a  value="上传" href="javascript:void(0)" style="width:40px;height:40px;position:absolute;" id="uploadImg">上传</a>
				　　　	　		<input type="file" name="file" style="position:absolute;width:40px;height:40px;top:0;left:0;z-index:1000;opacity:0" onchange="doUpload()"/>
				　　			</div>	
				    	</form>

                    </div>
                  </div>
                  
                  
              	  <div class="control-group">
                    <label class="control-label" >子节点说明:</label>
                    <div class="controls">
                      <input name="remark" id="remark"  maxlength="100"   type="text" class="w300"  value="${model.productChildNode.remark}"   />                      
                    </div>
                  </div>
                                                                  
                  </div>
                </div>

            </div>        
          </div>
          <div class="row-fluid">
          	<div class="footbtn"> 
          	<button class="btn btn-primary" type="submit"  onclick="save()">保存</button>
               <button class="btn" type="button" onclick="backIndex()">取消</button>
               </div>
          </div>
          </div>
      </div>    
  </body>
<script type="text/javascript">
	function downLoad(){
		var url=$('#imagea').attr("url");
		var fileName=$('#imagea').attr("fileName");
		var turl='${pageContext.request.contextPath}/common/file/download?url=' +encodeURIComponent(url) + "&fileName=" + encodeURIComponent(fileName);
		window.location.href=turl;
	}
	function doUpload() {  
		var domainUrl="${pageContext.request.contextPath}/common/file/upload";
		layer.load(1, {shade: [0.5,'#fff']});
	     var formData = new FormData($("#uploadForm")[0]);   
	     $.ajax({   
	          url: domainUrl,   
	          type: 'POST',   
	          data: formData,   
	          async: false,   
	          cache: false,   
	          contentType: false,   
	          processData: false,   
	          success: function (resultdata) {   
	              	//alert(returndata);  
	        	  layer.closeAll();
	              if(resultdata.returnCode=="0000"){               	
	              		// alert(resultdata.fileName);
	              		$('#imagea').attr("url",resultdata.url);
	              		$('#imagea').attr("fileName",resultdata.fileName);
	              		$('#imagea').html(resultdata.fileName);
	         
	              }else{
	              	//layer.alert(resultdata.returnMessage);
	              }
	          },   
	          error: function (returndata) {   
	        	  layer.alert('上传失败');
	          }   
	     });   
	} 
	</script>
  <script type="text/javascript">
  function save(){
		var postData="childNodeId=" +$('#childNodeId').val() ;
		
		
		var nodeId=$('#nodeId').val();
		if(nodeId==''){
			layer.alert('请选择产品节点');
	    	return;
		}
		postData=postData + "&nodeId=" + nodeId;
		
		var childNodeName=$('#childNodeName').val();
		if(childNodeName==''){
			layer.alert('请输入子节点名称');
	    	return;
		}
		postData=postData + "&childNodeName=" + encodeURIComponent(childNodeName);
		
		
		var isRequired= $("input[name='isRequired']:checked").val();
		if(isRequired==undefined){
			layer.alert('请选择是否必填');
	    	return;
		}
		postData=postData + "&isRequired=" + isRequired;
		
		var isEffectChild= $("input[name='isEffectChild']:checked").val();
		if(isEffectChild==undefined){
			layer.alert('请选择是否影响后续流程');
	    	return;
		}
		postData=postData + "&isEffectChild=" + isEffectChild;
		
		
		postData=postData + "&templateUrl=" + encodeURIComponent($('#imagea').attr("url"));
		postData=postData + "&fileName=" + encodeURIComponent($('#imagea').attr("fileName"));
		postData=postData + "&remark=" + encodeURIComponent($('#remark').val());
		
	    layer.load(1, {shade: [0.5,'#fff']});
	   //alert(postData);
	    $.ajax({
	        type: "POST",
	        url: "save",
	        data: postData,
	        contentType: "application/x-www-form-urlencoded;charset=UTF-8",
	        async: true, // 同步  true 异步。默认是异步
	        dataType: 'json',
	        error: function(resultdata) {
	        	layer.closeAll();
	        },
	        success: function(resultdata) {
	        	layer.closeAll();
	            if(resultdata.returnCode=="0000"){               	
	            	layer.alert('操作成功',{icon: 1}, function(){
	            	 	 parent.editReturn();
	            		//layer.closeAll(); 
	            		 //layer.closeAll();
	            		//window.location.href="${pageContext.request.contextPath}/distrbutor/inventory/index";
	            	});
	            }else{
	            	layer.alert(resultdata.returnMessage);
	            }
	        }
	    });
	}
  function backIndex(){	  
 	 parent.editReturn();
  }
	</script>
</html>
    